# -*- coding: utf-8 -*-
# @File : .py
# @Author : ZhouHang
# @Date : 20-4-8
# @Desc :
from celery_tasks.sms.utils.yuntongxun.sms import CCP
import logging
from celery_tasks.main import celery_app

logger = logging.getLogger('django')


@celery_app.task(name='send_msg')
def send_msg(mobile, sms_code, expire_mobile_code):
    """发送短信逻辑"""
    try:
        ccp = CCP()
        result = ccp.send_template_sms(mobile, [sms_code, expire_mobile_code], 1)
    except Exception as e:
        logger.error('发送短信异常, mobile:%s' % mobile)

    else:
        if result == 0:
            logger.info('发送短信成功 mobile:%s 验证码: %s' % (mobile, sms_code))

        else:
            logger.info('发送短信失败 mobile:%s' % mobile)
